package com.cyf.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;

/**
 * @author cyf
 * @description
 * @create 2018-09-14 17:46
 **/
public class DynamicProxy implements InvocationHandler {

    private Object target;

    private static Map<String,Object> map = null;

    static {
        map = new HashMap();
        map.put("key","value");
    }

    public DynamicProxy(Object obj) {
        this.target = obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return method.invoke(target,args);
    }

    public static void main(String[] args) {

        UserService userServiceImpl = new UserServiceImpl();
        InvocationHandler handler = new DynamicProxy(userServiceImpl);
        UserService userService = (UserService) Proxy.newProxyInstance(handler.getClass().getClassLoader(), userServiceImpl.getClass().getInterfaces(), handler);
        userService.save();
    }


}
